export type ToolInput = unknown;
export type ToolResult = unknown;

export interface ToolContext {
  /** Emit a diagnostic or log (pluggable). */
  log?: (msg: string) => void;
}

export interface Tool {
  name: string;
  description?: string;
  run(input: ToolInput, ctx?: ToolContext): Promise<ToolResult> | ToolResult;
}

export class ToolRegistry {
  private tools = new Map<string, Tool>();

  register(tool: Tool) {
    this.tools.set(tool.name, tool);
  }

  get(name: string): Tool | undefined {
    return this.tools.get(name);
  }

  list(): Tool[] {
    return Array.from(this.tools.values());
  }
}

// Built-in tools for demonstration
export const builtInTools = {
  echo: {
    name: 'echo',
    description: 'Echo back the input',
    run: async (input: any) => ({ echoed: input })
  } as Tool,

  view: {
    name: 'view',
    description: 'View file content (simulated)',
    run: async (input: any) => {
      const { path } = input as { path: string };
      return {
        content: `// Simulated content of ${path}\nconsole.log('Hello from ${path}');`,
        lines: 2
      };
    }
  } as Tool,

  remember: {
    name: 'remember',
    description: 'Create a memory item',
    run: async (input: any) => {
      const { content } = input as { content: string };
      return {
        memoryId: `mem_${Date.now()}`,
        content,
        status: 'queued_for_review'
      };
    }
  } as Tool
};

